/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package form;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import negocio.Persona;
import sql.Conexion;

/**
 *
 * @author Alumno
 */
public class Ordenar extends javax.swing.JFrame {
       
  //  String titulo[] = {"Rut","rut-ver","nombre","Apellido P","Apellido M","Sueldo Base", "Carga", "Movilizaciob", "Colacion","Fecha"};
   // DefaultTableModel modelo = new DefaultTableModel(titulo,0);
    /**
     * Creates new form Ordenar
     */
    public Ordenar() {
        initComponents();
        
    }
    
    void listar()
    {
        Conexion con = new Conexion();
        
        
       // modelo = con.listar();         
       //  j_tabla.setModel(modelo);
       
      
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        radioRutAsc = new javax.swing.JRadioButton();
        radioRutDesc = new javax.swing.JRadioButton();
        radioApellidoAsc = new javax.swing.JRadioButton();
        radioApellidoDesc = new javax.swing.JRadioButton();
        btnOrdenarRut = new javax.swing.JButton();
        btnOrdenarApellido = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        j_area = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Rut");

        jLabel2.setText("Apellido P.");

        radioRutAsc.setText("ASC");
        radioRutAsc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioRutAscActionPerformed(evt);
            }
        });

        radioRutDesc.setText("DESC");
        radioRutDesc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioRutDescActionPerformed(evt);
            }
        });

        radioApellidoAsc.setText("ASC");
        radioApellidoAsc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioApellidoAscActionPerformed(evt);
            }
        });

        radioApellidoDesc.setText("DESC");
        radioApellidoDesc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioApellidoDescActionPerformed(evt);
            }
        });

        btnOrdenarRut.setText("Aceptar");
        btnOrdenarRut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOrdenarRutActionPerformed(evt);
            }
        });

        btnOrdenarApellido.setText("Aceptar");
        btnOrdenarApellido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOrdenarApellidoActionPerformed(evt);
            }
        });

        jButton3.setText("Limpiar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Ordenar");

        j_area.setColumns(20);
        j_area.setRows(5);
        jScrollPane2.setViewportView(j_area);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(radioRutAsc)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(radioRutDesc)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnOrdenarRut))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(radioApellidoAsc)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(radioApellidoDesc)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnOrdenarApellido)))
                        .addGap(85, 85, 85)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(239, 239, 239)
                        .addComponent(jLabel3)))
                .addContainerGap(87, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(4, 4, 4)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(radioRutAsc)
                            .addComponent(radioRutDesc)
                            .addComponent(btnOrdenarRut))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(radioApellidoAsc)
                            .addComponent(radioApellidoDesc)
                            .addComponent(btnOrdenarApellido))
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOrdenarRutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOrdenarRutActionPerformed
        
        int registro[] = null;
        int asc[] = null;
        
        if(radioRutAsc.isSelected())
        {
           Conexion con = new Conexion();
           
          registro = con.ordenarRutAsc();
          //prueba 
          //int prueba[] = {3,500,756,245,9753157,3465632,67567658,55345,234};
          asc = con.shellSort(registro);
          
         // JOptionPane.showMessageDialog(null, asc[0]);
          j_area.setText(null);
          String ordenado = "";
          for(int conta = 0; asc.length > conta; conta++)
          {
              System.out.println(asc[conta]);  
              ordenado = ordenado+asc[conta]+"\n";
              j_area.setText(String.valueOf(ordenado));
              
          }
        }
        else
        {
            
        }
       
    }//GEN-LAST:event_btnOrdenarRutActionPerformed

    private void radioRutAscActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioRutAscActionPerformed
        
        if(radioRutAsc.isSelected())
        {
            radioRutDesc.setSelected(false);
        }
    }//GEN-LAST:event_radioRutAscActionPerformed

    private void radioRutDescActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioRutDescActionPerformed
       
        if(radioRutDesc.isSelected())
        {
            radioRutAsc.setSelected(false);
        }
    }//GEN-LAST:event_radioRutDescActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        j_area.setText(null);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void radioApellidoAscActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioApellidoAscActionPerformed
        if(radioApellidoAsc.isSelected())
        {
            radioApellidoDesc.setSelected(false);
        }
       
    }//GEN-LAST:event_radioApellidoAscActionPerformed

    private void btnOrdenarApellidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOrdenarApellidoActionPerformed
        
        if(radioApellidoAsc.isSelected())
        {
            
            Conexion con = new Conexion();
            String[] apellido = con.sortStringAsc();
            
            j_area.setText(null);
            String ordenado = "";
            for(int i=0; i<apellido.length;i++)
            {
                System.out.println(apellido[i]);
                
                ordenado = ordenado+apellido[i]+"\n";
                j_area.setText(ordenado);
            }
            
           // modelo.addRow(apellido);
            
        }
        else
        {
            Conexion con = new Conexion();
            String[] apellido = con.sortStringDesc();
            
            for(int i=0; i<apellido.length;i++)
            {
                System.out.println(apellido[i]);
            }
            
          //  modelo.addRow(apellido);
            
        }
    }//GEN-LAST:event_btnOrdenarApellidoActionPerformed

    private void radioApellidoDescActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioApellidoDescActionPerformed
       if(radioApellidoDesc.isSelected()){
           radioApellidoAsc.setSelected(false);
       }
    }//GEN-LAST:event_radioApellidoDescActionPerformed

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOrdenarApellido;
    private javax.swing.JButton btnOrdenarRut;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea j_area;
    private javax.swing.JRadioButton radioApellidoAsc;
    private javax.swing.JRadioButton radioApellidoDesc;
    private javax.swing.JRadioButton radioRutAsc;
    private javax.swing.JRadioButton radioRutDesc;
    // End of variables declaration//GEN-END:variables
}
